﻿using System;
using System.Globalization;
using System.Numerics;
using System.Windows;
using System.Windows.Data;

namespace DsaPrimeGenerator.Converters
{
    [ValueConversion(typeof(BigInteger), typeof(string))]
    public class BigIntegerConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            BigInteger bigInteger = (BigInteger)value;
            return bigInteger.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string stringBigInteger = value.ToString();
            BigInteger bigInteger;
            if (BigInteger.TryParse(stringBigInteger, out bigInteger))
            {
                return bigInteger;
            }
            else
            {
                return DependencyProperty.UnsetValue;
            }
        }
    }
}

